<?php

namespace App\Lib;
use \GatewayWorker\Lib\DbConnection;

class Db
{
    public static $db       = [] ;
    public static $conf     = [
        'host'=>'127.0.0.1',
        'port'=>'3306',
        'user'=>'nhzlc',
        'password'=>'nhzlc190614',
        'db_name'=>'nhzlc'
    ];

    /* 
    use \app\lib\db;
    $db = db::init()->query("SELECT * FROM `qii_config` limit 1");

    $db = \app\lib\db::init()->query("SELECT * FROM `qii_config` limit 1");
    */
    public static function init(){
        if ( empty( self::$db ) ) {
            try {
                $db = new DbConnection(
                    self::$conf['host'], 
                    self::$conf['port'], 
                    self::$conf['user'], 
                    self::$conf['password'], 
                    self::$conf['db_name'],
                    'utf8mb4' // utf8mb4 utf8
                );
                self::$db   = $db ;
            } catch (\Exception $e) {
                return false;
            }
        }
        return self::$db;
    }
}